package com.xinhua.erp.pojo;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.xinhua.erp.utils.JsonLongSerializer;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

@Entity
public class Role {
    @Id
    @JsonSerialize(using = JsonLongSerializer.class)
    private Long id;

    private String name;

    private String description;

    @ManyToMany(cascade = CascadeType.REFRESH)
    @JoinTable(name = "role_authority", inverseJoinColumns = @JoinColumn(name = "authority_id"), joinColumns = @JoinColumn(name = "role_id"))
    private Set<Authority> authoritySet = new HashSet<>();
    public Set<Authority> getAuthoritySet() {
        return authoritySet;
    }

    public void setAuthoritySet(Set<Authority> authoritySet) {
        this.authoritySet = authoritySet;
    }

    @ManyToMany(cascade = CascadeType.REFRESH, mappedBy = "roleSet", fetch = FetchType.LAZY)
    private Set<User> userSet = new HashSet<>();

    public Set<User> getRoleSet() {
        return userSet;
    }

    public void setRoleSet(Set<User> roleSet) {
        this.userSet = roleSet;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description == null ? null : description.trim();
    }
}